#include "login.h"
#include "ui_login.h"

login::login(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::login)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint);      // 隐藏边框
    this->setAttribute(Qt::WA_TranslucentBackground);     // 背景透明
    // 设置密码框输入不可见
    ui->password->setEchoMode(QLineEdit::Password);
}

login::~login()
{
    delete ui;
}

void login::on_login_btn_clicked()
{
    QString temp = ui->username->text();
    if(temp == 0) {
        QMessageBox::information(this, tr("操作提示"),
                                 tr("用户名或密码不能为空"),
                                 QMessageBox::Ok);
        emit failed();
        return;
    }
    id = temp.toInt();
    password = ui->password->text();
    // 连接数据库：
    dbase = new DbOperator();
    dbase->OpenDb();
    // 查询用户信息：
    msg = dbase->searchTrainerMsg(id);

    if(password == msg.password) {
        emit success(id);
        this->close();
        delete dbase;
        dbase = 0;
    }
    else {
        QMessageBox::information(this, tr("用户名或密码错误"),
                                 tr("用户名或密码错误"),
                                 QMessageBox::Ok);
        emit failed();
    }
}
